package io.renren.modules.user.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import io.renren.modules.generator.entity.TTrainingEntity;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.user.entity.TPeopleFireDetachmentEntity;
import io.renren.modules.user.service.TPeopleFireDetachmentService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 支队类型表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-09 13:03:54
 */
@RestController
@RequestMapping("/tpeoplefiredetachment")
public class TPeopleFireDetachmentController extends AbstractController {
    @Autowired
    private TPeopleFireDetachmentService tPeopleFireDetachmentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("user:tpeoplefiredetachment:list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = tPeopleFireDetachmentService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("user:tpeoplefiredetachment:info")
    public R info(@PathVariable("id") Integer id){
		TPeopleFireDetachmentEntity tPeopleFireDetachment = tPeopleFireDetachmentService.getById(id);

        return R.ok().put("tPeopleFireDetachment", tPeopleFireDetachment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("user:tpeoplefiredetachment:save")
    public R save(@RequestBody TPeopleFireDetachmentEntity tPeopleFireDetachment){
		tPeopleFireDetachmentService.save(tPeopleFireDetachment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("user:tpeoplefiredetachment:update")
    public R update(@RequestBody TPeopleFireDetachmentEntity tPeopleFireDetachment){
		tPeopleFireDetachmentService.updateById(tPeopleFireDetachment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("user:tpeoplefiredetachment:delete")
    public R delete(@RequestBody Integer[] ids){
		tPeopleFireDetachmentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/listDept")
    public R listDept(@RequestBody TPeopleFireDetachmentEntity tPeopleFire){
        String parentId="" ;
        if(tPeopleFire.getParentId()!=null){
            parentId=tPeopleFire.getParentId()+"";
        }
        String squadron = tPeopleFire.getSquadron();
        List<TPeopleFireDetachmentEntity>  tPeopleFireList= tPeopleFireDetachmentService.listDept(parentId,squadron);
        return R.ok().put("data",tPeopleFireList);
    }

    @RequestMapping("/listZDept")
    public R listZDept(@RequestBody TPeopleFireDetachmentEntity tPeopleFire){
        String deptId="" ;
        if(tPeopleFire.getId()!=null){
            deptId=tPeopleFire.getId()+"";
        }
        String parentId="";
        if(tPeopleFire.getParentId()!=null){
            parentId=tPeopleFire.getParentId()+"";
        }
        List<TPeopleFireDetachmentEntity>  tPeopleFireList= tPeopleFireDetachmentService.listZDept(parentId,deptId);
        return R.ok().put("data",tPeopleFireList) ;
    }



    /**
     * 列表
     */
    @RequestMapping("/organizationalStructure")
    //@RequiresPermissions("generator:tobject:selectTTraining")
    public R selectList(@RequestBody TPeopleFireDetachmentEntity tPeopleFire){
        Map<String,Object> params=new HashMap<String,Object>();
        params.put("page",tPeopleFire.getPage());
        params.put("limit",tPeopleFire.getLimit());
        PageUtils page = tPeopleFireDetachmentService.organizationalStructure(params);
        return R.ok().put("page", page);

    }

}
